﻿@{
    ViewBag.Title = "DataSelectForm";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    //var options = {
    //    keyValue: request('keyValue'),
    //    type: request('type'),  // 0词典  1 业户  2公共区域  3员工（All）  4会员  5房产  6供应商   10设备 11工作项目 
    //    category: request('category'), //0 无业务  11-维修派单人 12-维修处理人（自修）13-维修处理人（外派）14-维修回访人  21-投诉派单人 22-投诉立项人 23-投诉处理人  24-投诉回访人 31-联系处理人
    //    organizeid: request('organizeid'),
    //    itemId: request('itemId'), //词典类别
    //    data:[id text value],//数据域
    //    url: ""
    //};
    var options = JSON.parse(request('options'));
    var PStructId = "";
    var WorkerId = "";
    var WorkerType = -1;
    $(function () {
        debugger;
        InitialPage();
    });

    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth($('.gridPanel').width());
                $("#gridTable").setGridHeight($(window).height() - 141.5);
                $("#itemTree").setTreeHeight($(window).height() - 51.5);
            }, 200);
            e.stopPropagation();

        });

        //组织机构
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            description: "==请选择组织机构==",
            height: "250px",
            click: function (item) {
                options.organizeid = item.id;
                GetTree();
                $('#btn_Search').trigger("click");
            }
        });
        if (options.organizeid != "") $("#OrganizeId").ComboBoxTreeSetValue(options.organizeid);
        $("#OrganizeId").attr("disabled", "disabled");

        GetTree();
    }


    function GetTree() {
        debugger;
        var item = {};
        switch (parseInt(options.type)) {
            case 0: {
                //词典
                $("#itemTree").attr("disabled", "disabled");
                GetGrid3();
            }; break;
            case 1: {
                //业户
                options.url = "../../ResourceManage/RS_PStructs/GetTreeJson?type=5&organizeid=" + options.organizeid;
                item = {
                    url: options.url,
                    onnodeclick: function (item) {
                        PStructId = item.id;
                        GetGrid1();
                        $('#btn_Search').trigger("click");
                    }
                };
                $("#itemTree").treeview(item);
            }; break;
            case 2: {
                options.url = "../../ResourceManage/RS_PStructs/GetTreeJson?type=4&organizeid=" + options.organizeid;//维修地点公共区域
                item = {
                    url: options.url,
                    onnodeclick: function (item) {
                        PStructId = item.id;
                        GetPublicAreaGrid();
                        $('#btn_Search').trigger("click");
                    }
                };
                $("#itemTree").treeview(item);
                GetPublicAreaGrid();
                $("#queryCondition").html("");
                $("#txt_Keyword").attr("placeholder", "请输入编码或名称查询");
            }; break;
            case 3: {
                //员工
                options.url = "../../BaseManage/Worker/GetWorkerTreeJson?organizeid=" + options.organizeid;
                WorkerType = options.category != undefined ? options.category : -1;
                debugger;
                if (WorkerType > -1) {
                    $("#itemTree").attr("disabled", "disabled");
                }
                else {                   
                    item = {
                        url: options.url,
                        onnodeclick: function (item) {
                            WorkerId = item.id;
                            GetGrid2();
                            $('#btn_Search').trigger("click");
                        }
                    };
                    $("#itemTree").treeview(item);
                }                
                GetGrid2();
            }; break;//员工机构部门树
            case 4: //会员
                GetMemberGrid();
                break;
            case 5: //房产
                var queryJson = options.queryJson;
                var item = {
                    height: $(window).height() - 51.5,
                    url: "../../ResourceManage/RS_PStructs/GetTreeJson?IsSubstep=true&organizeid=" + options.organizeid + "&type=" + options.PstructType,
                    onnodeclick: function (item) {
                        if (PStructId != item.id) {
                            PStructId = item.id;
                            $('#btn_Search').trigger("click");
                        }
                    }
                };
                //初始化
                $("#itemTree").treeview(item);
                GetPstructGrid();
                break;
            case 6://供应商
                GetVendorGrid();
                break;
            case 10:
                GetGrid4();
                break;
            case 11: //工作项目
                options.url = "../../PropertyManage/CS_DeviceMaintance/GetWorkTypeTreeJson";
                item = {
                    url: options.url,
                    onnodeclick: function (item) {
                        WorkerId = item.Id;
                        GetGrid5();
                    }
                };
                $("#itemTree").treeview(item);
                GetGrid5();
                break;
            default: dialogMsg("目前没有数据，请先配置基础数据。", -1); break;
        }
      
    }

    //业户
    function GetGrid1() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["PStructId"] = PStructId;
        queryJson["OrganizeId"] = options.organizeid;
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_PStructUser/GetListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "id", index: "id", hidden: true },
                { label: "房间Id", name: "pstructid", index: "pstructid", hidden: true },
                { label: "关联关系ID", name: "relationpcid", index: "relationpcid", hidden: true },
                {
                    label: "客户类型", name: "type", index: "type", width: 70, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 2 ? "<span>租户</span>" : "<span>业主</span>";
                    }
                },
                { label: "客户名称", name: "name", index: "name", width: 150, align: "left" },
                { label: "客户编号", name: "code", index: "code", width: 150, align: "left" },
                { label: "手机号码", name: "phonenum", index: "phonenum", width: 250, align: "left" },
                { label: "房间面积", name: "area", index: "area", width: 150, align: "left" },

               { label: "所属房间", name: "pstructname", index: "pstructname", width: 150, align: "left" },

            ],
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Code',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var rowData = $("#gridTable").jqGrid("getRowData", selectedRowIndex);
                if (options.data != null) {
                    for (var i = 0; i < options.data.length; i++) {
                        if (options.data[i].id == "PStructId") {
                            options.data[i].text = rowData.pstructname;
                            options.data[i].value = rowData.pstructid;
                        }
                        else if (options.data[i].id == "CustomerName" || options.data[i].id == "CustomerId") {
                            options.data[i].text = rowData.name;
                            options.data[i].value = rowData.id;
                        }
                        else if (options.data[i].id == "Cname" || options.data[i].id == "LinkMan" || options.data[i].id == "ComplaintMan" || options.data[i].id == "RepairMan" || options.data[i].id == "ComplaintedManType" || options.data[i].id == "ComplaintedMan") {
                            options.data[i].text = rowData.name;
                            options.data[i].value = rowData.id;
                        }
                        else if (options.data[i].id == "Ccode") {
                            options.data[i].text = rowData.code;
                            options.data[i].value = rowData.code;
                        }
                        else if (options.data[i].id == "Area") {
                            options.data[i].text = rowData.area;
                            options.data[i].value = rowData.area;
                        }
                        else if (options.data[i].id == "CLphone" || options.data[i].id == "LinkPhone" || options.data[i].id == "ComplaintPhone" || options.data[i].id == "TellPhone" || options.data[i].id == "ComplaintedPhone") {
                            options.data[i].text = rowData.phonenum;
                            options.data[i].value = rowData.phonenum;
                        }
                        else if (options.data[i].id == "CustomerCode") {
                            options.data[i].text = rowData.code;
                            options.data[i].value = rowData.code;
                        }
                    }
                }
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#filter-form").GetWebControls();
            queryJson["PStructId"] = PStructId;
            queryJson["OrganizeId"] = options.organizeid;
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid')
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //员工
    function GetGrid2() {
        var selectedRowIndex = 0;
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
        queryJson["keyword"] = $("#txt_Keyword").val();
        queryJson["organizeId"] = options.organizeid;
        queryJson["departmentId"] = WorkerId;
        queryJson["Type"] = WorkerType;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../BaseManage/Worker/GetBussinessPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 136.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'id', hidden: true },
                { label: '工号', name: 'code', index: 'code', width: 100, align: 'left' },
                { label: '姓名', name: 'name', index: 'name', width: 100, align: 'left' },
                { label: '手机', name: 'phonenum', index: 'phonenum', width: 100, align: 'center' },
                { label: '职位', name: 'dutyname', index: 'dutyname', width: 100, align: 'left' },
                { label: '岗位', name: 'postname', index: 'postname', width: 100, align: 'left' },
                {
                    label: '角色', name: 'roleid', index: 'roleid', width: 100, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return top.clientroleData[cellvalue] == null ? "" : top.clientroleData[cellvalue].FullName;
                    }
                }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'code asc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var rowData = $("#gridTable").jqGrid("getRowData", selectedRowIndex);
                if (options.data != null) {
                    for (var i = 0; i < options.data.length; i++) {
                        if (options.data[i].id == "Person" || options.data[i].id == "ReturnPerson" || options.data[i].id == "ComplaintedMan" || options.data[i].id == "ProjectedMan"
                            || options.data[i].id == "SendMan" || options.data[i].id == "ReceiveMan" || options.data[i].id == "ExecMan" || options.data[i].id == "ReturnBackManId" 
                            || options.data[i].id == "BXRMan"||options.data[i].id == "CheckUserName"||options.data[i].id == "SettlementUserName"||options.data[i].id == "SignUserName"
                            ||options.data[i].id == "UserName"||options.data[i].id == "RepairMan") {
                            options.data[i].text = rowData.name;
                            options.data[i].value = rowData.id;
                        }
                        if (options.data[i].id == "ComplaintedPhone"||options.data[i].id == "BXLinkPhone"||options.data[i].id == "RealPhone"||options.data[i].id == "TellPhone") {
                            options.data[i].text = rowData.phonenum;
                            options.data[i].value = rowData.phonenum;
                        }

                        if (options.data[i].id == "ExecRole"||options.data[i].id == "CheckMan"||options.data[i].id == "PlanMan"||options.data[i].id == "RealMan"
                            ) {
                            options.data[i].text = rowData.name;
                            options.data[i].value = rowData.name;
                        }


                        if (options.data[i].id == "ExecRoleId" || options.data[i].id == "SendManId" || options.data[i].id == "ReceiveManId" || options.data[i].id == "ReceiveManId"
                            ||options.data[i].id == "ExecManId"||options.data[i].id == "CheckManId"||options.data[i].id == "PlanManId"||options.data[i].id == "RealManId"
                            ) {
                            options.data[i].text = rowData.id;
                            options.data[i].value = rowData.id;
                        }
                    }
                }
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //$gridTable.authorizeColModel()
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
            queryJson["keyword"] = $("#txt_Keyword").val();
            queryJson["organizeId"] = options.organizeid;
            queryJson["departmentId"] = WorkerId;
            queryJson["Type"] = WorkerType;
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }, page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //会员
    function GetMemberGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = $("#filter-form").GetWebControls();
        $gridTable.jqGrid({
            url: "../../QualificationManage/Member/GetListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "会员名称", name: "Name", index: "Name", width: 150, align: "left" },
                { label: "会员编号", name: "Code", index: "Code", width: 150, align: "left" },
                {
                    label: "性别", name: "Sex", index: "Sex", width: 70, align: "center",
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case 1: return "男";
                            case 2: return "女";
                            default: return "";
                        }
                    }
                },
                {
                    label: "会员状态", name: "State", index: "State", width: 70, align: "center",
                    formatter: function (cellvalue) {
                        return cellvalue == 0 ? "<span class=\"label label-danger\">无效</span>" : "<span class=\"label label-success\">有效</span>";
                    }
                },
                { label: "手机号码", name: "Phone", index: "Phone", width: 100, align: "left" },
                { label: "身份证号", name: "IDCard", index: "IDCard", width: 100, align: "left" },
                { label: "固定电话", name: "PhoneNum", index: "PhoneNum", width: 100, align: "left" },
                {
                    label: "婚姻状况", name: "MarryInfo", index: "MarryInfo", width: 150, align: "left", sortable: false,
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case "1": return "未婚";
                            case "2": return "已婚无子女";
                            case "3": return "已婚有子女";
                            case "4": return "离婚、离异无子女";
                            case "5": return "离婚、离异有子女";
                            default: return "未婚";
                        }
                    }
                },
                { label: "公司名称", name: "CompanyName", index: "CompanyName", width: 150, align: "left" },
                { label: "备注", name: "Description", index: "Description", width: 200, align: "left" }
            ],
            viewrecords: true,
            rowNum: 10000,
            sortname: 'MemberID',
            sortorder: 'asc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var rowData = $("#gridTable").jqGrid("getRowData", selectedRowIndex);
                if (options.data != null) {
                    for (var i = 0; i < options.data.length; i++) {
                        if (options.data[i].id == "Name") {
                            options.data[i].text = rowData.Name;
                            options.data[i].value = rowData.Id;
                        }
                        if (options.data[i].id == "MemberCode") {
                            options.data[i].text = rowData.Code;
                            options.data[i].value = rowData.Code;
                        }
                        if (options.data[i].id == "Phone") {
                            options.data[i].text = rowData.Phone;
                            options.data[i].value = rowData.Phone;
                        }
                    }
                }
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value);
            $("#btn_Search").trigger("click");
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#filter-form").GetWebControls();
            queryJson["Code"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "Code" ? $("#txt_Keyword").val() : "",
           queryJson["Name"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "Name" ? $("#txt_Keyword").val() : "",
           queryJson["NickName"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "NickName" ? $("#txt_Keyword").val() : "",
           queryJson["Phone"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "Phone" ? $("#txt_Keyword").val() : "",
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //房产
    function GetPstructGrid() {
        var HouseType, HouseTypeName;
        $.SetForm({
            url: "../../SystemManage/DataItemDetail/GetDataItemListJson",
            param: { EnCode: "HouseDirect" },
            success: function (data) {
                HouseType = data;
            }
        });

        $.SetForm({
            url: "../../SystemManage/DataItemDetail/GetDataItemListJson",
            param: { EnCode: "HouseType" },
            success: function (data) {
                HouseTypeName = data;
            }
        });
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["PStructId"] = PStructId;
        queryJson["OrganizeId"] = options.organizeid;
        queryJson["Type"] = options.PstructType;
        queryJson["IsPuslish"] = options.queryJson;
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_PStructs/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 111.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'id', hidden: true },
                { label: '公司Id', name: 'organizeid', hidden: true },
                { label: "房产名称", name: "name", width: 150, align: "left", sortable: true },
                {
                    label: "房产编号", name: "code", width: 100, align: "left", sortable: true
                },
                { label: "房产全名", name: "allname", width: 150, align: "left", sortable: true },
                { label: "建筑面积", name: "area", width: 100, align: "left", sortable: true },
                { label: "规划业态", name: "planningformat", width: 100, align: "left", sortable: true, hidden: true },
                {
                    label: "状态", name: "state", width: 100, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "准备房";
                            case 1: return "待租";
                            case 2: return "已选取";
                            case 3: return "已租";
                            case 4: return "自用";
                            case 5: return "已售";
                            case 6: return "续租中";
                            case 7: return "维修中";
                            default: return "";
                        }
                    }
                },
                {
                    label: "户型", name: "housetypename", width: 100, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        var Name = "";
                        $(HouseTypeName).each(function (index, data) {
                            if (data.ItemValue == cellvalue) {
                                Name = data.ItemName;
                                return;
                            }
                        });
                        return Name;
                    }
                },
                {
                    label: "朝向", name: "housetype", width: 100, align: "left", sortable: true,
                    //formatter: function (cellvalue, options, rowObject) {
                    //    var Name = "";
                    //    $(HouseType).each(function (index, data) {
                    //        if (data.ItemValue == cellvalue) {
                    //            Name = data.ItemName;
                    //            return;
                    //        }
                    //    });
                    //    return Name;
                    //}
                },
                { label: "月租金", name: "monthlyrent", width: 100, align: "left", sortable: true },
                {
                    label: "起租日期", name: "emoveindate", width: 100, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                },
                {
                    label: "发布状态", name: "ispublish", index: "ispublish", width: 70, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case 0: return "未发布";
                            case 1: return "发布中";
                            case 2: return "已发布";
                            case 3: return "发布失败";
                            default: return "";
                        }
                    }
                },
                { label: "招租标题", name: "renttitle", width: 100, align: "left", sortable: true },
                    {
                        label: "是否审核", name: "auditmark", index: "auditmark", width: 150, align: "left", sortable: true, hidden: true,
                        formatter: function (cellvalue, options, rowObject) {
                            if (cellvalue == "1") {
                                return "<i class='fa fa-check fa-2x' style='color:green;margin-left:10px;' ><i/>";
                            }
                            else {
                                return "";
                            }
                        }
                    },
                { label: "附加说明", name: "memo", width: 100, align: "left", sortable: false },
            ],
            viewrecords: true,
            rowNum: 10000,
            sortable: true,
            sortname: 'code',
            sortorder: 'asc',
            rownumbers: false,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (rowid) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var rowData = $("#gridTable").jqGrid("getRowData", selectedRowIndex);
                if (options.data != null) {
                    for (var i = 0; i < options.data.length; i++) {
                        if (options.data[i].id == "RoomName") {
                            options.data[i].text = rowData.name;
                            options.data[i].value = rowData.id;
                        }
                        if (options.data[i].id == "AllName") {
                            options.data[i].text = rowData.allname;
                            options.data[i].value = rowData.id;
                        }
                    }
                }
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);

            }
        });

        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["PStructId"] = PStructId;
            queryJson["OrganizeId"] = options.organizeid;
            queryJson["keyword"] = $("#txt_Keyword").val();
            queryJson["Type"] = options.PstructType;
            queryJson["IsPuslish"] = options.queryJson;
            $gridTable.jqGrid('setGridParam', {
                postData: {
                    queryJson: JSON.stringify(queryJson)
                }
            }).trigger('reloadGrid');
        });
        //查询回车事件
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //供应商列表
    function GetVendorGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_Vendor/GetPageListJson",
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "名称", name: "FullName", index: "Name", width: 100, align: "left" },
                { label: "编号", name: "EnCode", index: "Code", width: 100, align: "left" },
                { label: "简称", name: "ShortName", index: "ShortName", width: 150, align: "left" },
                { label: "性质", name: "Nature", index: "Nature", width: 150, align: "center" },
                { label: "经营范围", name: "BusinessScope", index: "BusinessScope", width: 150, align: "center" },
                { label: "负责人名称", name: "Manager", index: "Manager", width: 150, align: "center" },
            ],
            rowNum: 10000,
            sortname: 'EnCode',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var rowData = $("#gridTable").jqGrid("getRowData", selectedRowIndex);
                debugger;
                if (options.data != null) {
                    for (var i = 0; i < options.data.length; i++) {
                        if (options.data[i].id == "CustomerId") {
                            options.data[i].text = rowData.FullName;
                            options.data[i].value = rowData.Id;
                        }
                        if (options.data[i].id == "Vendor") {
                            options.data[i].text = rowData.FullName;
                            options.data[i].value = rowData.Id;
                        }
                    }
                }
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            if (value == "Code") value = "EnCode";
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["keyword"] = $("#txt_Keyword").val();
            queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //词典表
    function GetGrid3() {
        var selectedRowIndex = 0;
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            url: "../../SystemManage/DataItemDetail/GetTreeListJson?itemId=" + options.itemId,
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'ItemDetailId', hidden: true },
                { label: '&nbsp;&nbsp;&nbsp;&nbsp;项目名', name: 'ItemName', index: 'ItemName', width: 200, align: 'left', sortable: false },
                  { label: '项目编号', name: 'ItemCode', index: 'ItemCode', width: 150, align: 'left', sortable: false },
                { label: '项目值', name: 'ItemValue', index: 'ItemValue', width: 200, align: 'left', sortable: false },
            ],
            treeGrid: true,
            treeGridModel: "nested",
            ExpandColumn: "ItemValue",
            rowNum: "10000",
            rownumbers: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var rowData = $("#gridTable").jqGrid("getRowData", selectedRowIndex);
                if (options.data != null) {
                    for (var i = 0; i < options.data.length; i++) {
                        if (options.data[i].id == "RepairedMemo") {
                            options.data[i].text = rowData.ItemName;
                            options.data[i].value = rowData.ItemCode;
                        }
                    }
                }
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                url: "../../SystemManage/DataItemDetail/GetTreeListJson",
                postData: {
                    itemId: options.itemId,
                    condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                    keyword: $("#txt_Keyword").val()
                },
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }
    //设备
    function GetGrid4() {
        var selectedRowIndex = 0;
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_Device/GetDeviceInfolist?keyValue=" + options.organizeid,
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
               { label: "主键", name: "Id", index: "Id", hidden: true },
               { label: "设备类别", name: "Type", index: "Type", width: 100, align: "left" },
               { label: "设备名称", name: "Name", index: "Name", width: 100, align: "left" },
               { label: "设备编号", name: "Code", index: "Code", width: 100, align: "left" },
               { label: "设备所属区域", name: "PStructId", index: "PStructId", width: 100, align: "left" },
               { label: "规格型号", name: "ModelNo", index: "ModelNo", width: 100, align: "left" },

                {
                    label: "状态", name: "State", index: "State", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? "<span class='label label-primary'>正常运行</span>" : "<span class='label label-danger'>故障停机</span>";
                    }
                },
               { label: "附加说明", name: "Description", index: "Description", width: 200, align: "left" }
            ],
            multiselect: true,
            ExpandColumn: "ItemValue",
            rowNum: "10000",
            rownumbers: true,
            onSelectRow: function (rowid, status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
                if (options.Name = "DeviceRepair") {
                    var rowIds = $gridTable.jqGrid('getDataIDs');
                    var ids = top.frames["Form"].$("#DeviceId").val();
                    for (var k = 0; k < rowIds.length; k++) {
                        var id = $gridTable.getRowData(rowIds[k]).Id;
                        if (ids.indexOf(id) >= 0) {
                            $gridTable.jqGrid("delRowData", rowIds[k]);
                        }
                    }
                }
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_Device/GetDeviceInfolist",
                postData: {
                    keyValue: options.organizeid,
                    condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                    keyword: $("#txt_Keyword").val()
                },
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }
    //工作项目
    function GetGrid5() {
        var selectedRowIndex = 0;
        var $gridTable = $("#gridTable");

        var queryJson = {
            keyValue: "",
            Type: WorkerId,
            OrganizeId: options.organizeid,
            condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
            keyword: $("#txt_Keyword").val()
        };
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_DeviceMaintance/GetWorkItemList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
               { label: "主键", name: "Id", hidden: true },
               { label: "项目编号", name: "Code", index: "Code", width: 200, align: "center", sortable: false },
               { label: "项目名称", name: "Name", index: "Name", width: 200, align: "center", sortable: false },
               { label: "工作类型", name: "Type", index: "Type", width: 200, align: "center", sortable: false },
               { label: "工作内容", name: "Memo", index: "Memo", width: 400, align: "center", sortable: false }
            ],
            viewrecords: true,
            treeGrid: true,
            rowNum: "10000",
            rownumbers: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var rowData = $("#gridTable").jqGrid("getRowData", selectedRowIndex);
                if (options.data != null) {
                    for (var i = 0; i < options.data.length; i++) {
                        if (options.data[i].id == "ItemName") {
                            options.data[i].text = rowData.Name;
                            options.data[i].value = rowData.Name;
                        }
                        if (options.data[i].id == "ItemId") {
                            options.data[i].text = rowData.Id;
                            options.data[i].value = rowData.Id;
                        }
                        if (options.data[i].id == "WeekPlanCode") {
                            options.data[i].text = rowData.Code;
                            options.data[i].value = rowData.Code;
                        }
                        if (options.data[i].id == "Memo") {
                            options.data[i].text = rowData.Memo;
                            options.data[i].value = rowData.Memo;
                        }
                    }
                }
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                keyValue: "",
                Type: WorkerId,
                OrganizeId: options.organizeid,
                condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_Keyword").val()
            };
            $gridTable.jqGrid('setGridParam', {
                postData: {
                    queryJson: JSON.stringify(queryJson)
                }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //加载表格
    function GetPublicAreaGrid() {
        var selectedRowIndex = 0;
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["OrganizeId"] = options.organizeid;
        queryJson["keyword"] = $("#txt_Keyword").val();
        queryJson["Type"] = "6";
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_PublicArea/GetPageListJson",
            datatype: "json",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'PCode', hidden: true },
                { label: 'OrganizeId', name: 'OrganizeId', hidden: true },
                { label: 'PStructID', name: 'PStructID', hidden: true },
                {
                    label: '审核标识', name: 'AuditFlag', hidden: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return rowObject.AuditMark;
                    }
                },
                { label: "公区名称", name: "Name", width: 200, align: "left", sortable: true },
                { label: "公区编号", name: "EnCode", width: 100, align: "left", sortable: true },
                { label: "房产全称", name: "PSAllName", width: 200, align: "left", sortable: true },
                 { label: "位置描述", name: "OtherCode", width: 200, align: "left", sortable: true },
                {
                    label: "标识方式", name: "FlagWay", width: 80, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "无标识";
                            case 1: return "rfid芯片";
                            case 2: return "条码";
                            case 3: return "二维码";
                            case 4: return "beacon";
                            default: return "";
                        }
                    }
                },
                { label: "标识编码", name: "FlagNo", width: 200, align: "left", sortable: true },
                {
                    label: "是否审核", name: "AuditMark", width: 80, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? " <i class='fa fa-check fa-2x' style='color:green;margin-left:10px;' ><i/>" : "";
                    }
                },
                { label: "审核人", name: "AuditMan", index: "AuditMan", width: 80, align: "left" },
                { label: "审核日期", name: "AuditDate", index: "AuditDate", width: 80, align: "left" },
                { label: "备注", name: "Memo", width: 200, align: "left", sortable: false }
            ],
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortable: true,
            sortname: 'Code',
            sortorder: 'asc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var rowData = $("#gridTable").jqGrid("getRowData", selectedRowIndex);
                if (options.data != null) {
                    for (var i = 0; i < options.data.length; i++) {
                        if (options.data[i].id == "PStructId") {
                            options.data[i].text = rowData.Name;
                            options.data[i].value = rowData.PStructID;
                        }
                    }
                }
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                Type: "6",
                keyword: $("#txt_Keyword").val(),
                PStructName: PStructId,
                OrganizeId: options.organizeid
            }
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }, page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }




    //保存表单
    function AcceptClick() {
        if (options.TopForm == "Tab") {
            for (var i = 0; i < options.data.length; i++) {
                var $obj = $.currentIframe().$("#" + options.data[i].id);
                $obj[0].value = options.data[i].text;
                $obj[0].title = options.data[i].value;
            }
            dialogClose();
            return false;
        }
        if (options.Name == "DeviceRepair") {
            var rowids = $("#gridTable").jqGrid('getGridParam', 'selarrrow');
            var JSONData = [], ids = "";
            for (var i = 0; i < rowids.length; i++) {
                var rowData = $('#gridTable').jqGrid('getRowData', rowids[i]);
                var data = {};
                data["DeviceId"] = rowData.Id;
                data["DeviceName"] = rowData.Name;
                data["DeviceCode"] = rowData.Code;
                data["PStructName"] = rowData.PStructId;
                JSONData.push(data);
                ids += rowData.Id + ",";
            }
            top.Form.$("#gridTable1")[0].addJSONData(JSONData);
            top.Form.$("#DeviceId").val(ids);
        }
        for (var i = 0; i < options.data.length; i++) {
            var $obj = top.Form.$("#" + options.data[i].id);
            $obj[0].value = options.data[i].text;
            $obj[0].title = options.data[i].value;
        }
        dialogMsg("操作成功。", 1);
        dialogClose();
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height: 98%;">
            <div class=" panel-title" style="padding:0px;"><div id="OrganizeId" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree" style=" height: 98%;"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="titlePanel">
            <div class="title-search">
                <table>
                    <tr>
                        <td>
                            <div id="queryCondition" class="btn-group">
                                <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li><a data-value="Code">编码</a></li>
                                    <li><a data-value="Name">名称</a></li>
                                </ul>
                            </div>
                        </td>
                        <td style="padding-left: 2px;">
                            <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                        </td>
                        <td style="padding-left: 5px;">
                            <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="center-Panel">
            <div class="gridPanel">
                <table id="gridTable"></table>
            </div>
        </div>
    </div>

</div>
